package com.example.itemtouchhelper

import android.graphics.Color
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.RecyclerView
import com.example.itemtouchhelper.entity.Bean
import com.example.itemtouchhelper.utils.ColorUtils

class CardActivity : AppCompatActivity() {
    private lateinit var contentList: MutableList<Bean>
    private lateinit var recyclerView: RecyclerView
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_card)
        init()
        recyclerView.layoutManager = CardLayoutManager()
        val cardAdapter = CardAdapter(contentList, this)
        recyclerView.adapter = cardAdapter
        ItemTouchHelper(CardItemTouchCallback(contentList, cardAdapter)).apply {
            attachToRecyclerView(recyclerView)
        }
    }

    private fun init() {
        recyclerView = findViewById(R.id.rv)
        contentList = mutableListOf()
        for (i in 1..20) {
            val bean = Bean("$i", Color.parseColor(ColorUtils.generateRandomColor()))
            contentList.add(bean)
        }
    }
}